require 'osx/cocoa'
include OSX
prefix = "com.apple.speech.synthesis.voice."
require 'enumerator'


VOICES = NSSpeechSynthesizer.availableVoices

def display_voices
  puts VOICES.to_enum(:each_with_index).map {|x, i| "[#{i}] " +  x.split('.')[-1] }.join("\t")
end


display_voices
puts "type the number of the voice, and a space, and what you want it to say"
while line = gets
  if line =~ /^\d/
    voice_index = Integer(line.split(" ")[0])
    line = line[1..-1]
  else
    voice_index = 0 unless voice_index # default voice
  end
  this_voice = VOICES[voice_index]

  display_voices 
  speech = NSSpeechSynthesizer.alloc.initWithVoice(this_voice)
  puts line
  speech.startSpeakingString(line)

end
